<?php
session_start(); 
if(!isset($_SESSION['userName'])){
header( 'location: ../index.php' ); 
}

include("../conf/connect.php");
	$user_id = $_SESSION['user_id'];
	$qus_no = $_GET['qus'];
	$hid = $_SESSION['usrHHid'];
	$resId =$_SESSION['lid'];
	$respondent=$_SESSION['hello'];
	

  if($qus_no =='hid'){
  		$house_id=$_POST['HHHid'];
    	$_SESSION['usrHHid']=$house_id ;
		$adult_check="SELECT * FROM adult_question where hid=$hid and user_id=$user_id";
		$adult_result = mysql_query($adult_check) or die ("problem budget_heads");
		$flag=0;
		while($row = mysql_fetch_assoc($adult_result)){
			$adult_resp_id=$row['resp_id'];
			if($adult_resp_id==''){
				$flag++;
			}
		}
		
		if($flag=='0'){
			$sql="INSERT INTO adult_question (id, hid, user_id, is_delete, status) 
					VALUES 
				('', '$hid','$user_id',  0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO chronic (id, hid, user_id,  is_delete, status) 
					VALUES 
				('', '$hid','$user_id', 0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: question.php?serial=member" );
		}
		else{
			header( "location: question.php?serial=member" );
		}
  } 
  if($qus_no =='member'){
    	$resp_id=$_POST['memid'];
		$_SESSION['hello']=$resp_id;
		
		$adult_check="SELECT * FROM adult_question where hid=$hid and user_id=$user_id";
		$adult_result = mysql_query($adult_check) or die ("problem budget_heads");
		$flag=0;
		while($row = mysql_fetch_assoc($adult_result)){
			$adult_resp_id=$row['resp_id'];
			if($adult_resp_id==$resp_id){
				$flag++;
			}
		}
				
		$adult_check="SELECT * FROM adult_question where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$adult_result = mysql_query($adult_check) or die ("problem budget_heads");
		$adult_row = mysql_fetch_assoc($adult_result);
		$adult_id=$adult_row['id'];
		
		$chronic_check="SELECT * FROM chronic where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$chronic_result = mysql_query($chronic_check) or die ("problem budget_heads");
		$chronic_row = mysql_fetch_assoc($chronic_result);
		$chronic_id=$chronic_row['id'];
		
		if($flag=='0'){	
			$sql="UPDATE adult_question set resp_id='$resp_id'  WHERE  hid ='$hid' and id='$adult_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");		
			$sql="UPDATE chronic set resp_id='$resp_id'  WHERE hid ='$hid' and id='$chronic_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		}
		header( "location: question.php?serial=emp01" );
  } 
  else if($qus_no =='emp01'){
  		$emp01 = $_POST["emp01"];
		$sql="UPDATE adult_question set emp01='$emp01'  WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($emp01=='0'){
			header( "location: question.php?serial=emp01" );
		}
		else{
			header( "location: question.php?serial=emp" );
		}	
  } 
  else if($qus_no =='emp'){
  		$emp02 = $_POST["emp02"];
		$emp03 = $_POST["emp03"];
		$emp04_a = $_POST["emp04_a"];
		$emp04_b = $_POST["emp04_b"];
		$emp05 = $_POST["emp05"];
		$emp06 = $_POST["emp06"];
		$emp07 = $_POST["income"];
		$sql="UPDATE adult_question set emp02='$emp02', emp03='$emp03', emp04_a='$emp04_a', emp04_b='$emp04_b', emp05='$emp05',emp06='$emp06',emp07='$emp07' WHERE  hid ='$hid' and resp_id='$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		$mql="SELECT * FROM adult_question WHERE hid ='$hid' and resp_id=$respondent";
				$result = mysql_query($mql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);
		if($row['emp01']=='1'){			
			if($emp04_a=='00'||$emp04_b=='00'||$emp05=='00'||$emp06=='00'||$emp07==''){
				//echo "hello";	
				header( "location: question.php?serial=emp" );
				exit;
			}			
		}
		elseif($row['emp01']=='2'){
			if($emp02=='00'||$emp03=='00'||$emp06=='00'||$emp07==''){
				header( "location: question.php?serial=emp" );
				exit;
			}
		}
				
		header( "location: question.php?serial=spn01" );
		
  } 
  else if($qus_no =='spn_01'){
  		$spn01_a = $_POST["spn01_a"];
		$spn01_b = $_POST["spn01_b"];
		$spn01_c = $_POST["spn01_c"];
		$spn01_d = $_POST["spn01_d"];
		$spn01_e = $_POST["spn01_e"];
		
		
  		$sql="UPDATE adult_question set spn01_a='$spn01_a', spn01_b='$spn01_b', spn01_c='$spn01_c', spn01_d='$spn01_d', spn01_e='$spn01_e' WHERE user_id='$user_id' and hid = '$hid' and resp_id = '$respondent'";
	mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		mysql_query($sql) or die ("problem budget_heads");
	if($spn01_a=='0'||$spn01_b=='0'||$spn01_c=='0'||$spn01_d=='0'||$spn01_e=='0'){
		header( "location: question.php?serial=spn01" );
	}
	elseif($spn01_a=='1'){
	    header( "location: question.php?serial=spn02a" );
	}
	elseif($spn01_b=='1'){
	    header( "location: question.php?serial=spn02b" );
	}
	elseif($spn01_c=='1'){
	    header( "location: question.php?serial=spn02c" );
	}
	elseif($spn01_d=='1'){
	    header( "location: question.php?serial=spn02d" );
	}
	elseif($spn01_e=='1'){
	    header( "location: question.php?serial=spn02e" );
	}
	else header("location: question.php?serial=gh01");	
		
  } 
  else if($qus_no =='spn02a'){
  		$spn02_a = $_POST["spn02_a"];
		$sql="UPDATE adult_question set spn02_a='$spn02_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_a=='0'){
			header( "location: question.php?serial=spn02a" );
		}
		elseif($spn02_a=='1'){
			header( "location: question.php?serial=spn02y" );
		}
		elseif($spn02_a=='3'){
			header( "location: question.php?serial=spn02n" );
		}	
  }
  else if($qus_no =='spn02b'){
  		$spn02_b = $_POST["spn02_b"];
		$sql="UPDATE adult_question set spn02_b='$spn02_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_b=='0'){
			header( "location: question.php?serial=spn02b" );
		}
		elseif($spn02_b=='1'){
			header( "location: question.php?serial=spn02by" );
		}
		elseif($spn02_b=='3'){
			header( "location: question.php?serial=spn02bn" );
		}	
  }
  else if($qus_no =='spn02c'){
  		$spn02_c = $_POST["spn02_c"];
		$sql="UPDATE adult_question set spn02_c='$spn02_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_c=='0'){
			header( "location: question.php?serial=spn02c" );
		}
		elseif($spn02_c=='1'){
			header( "location: question.php?serial=spn02cy" );
		}
		elseif($spn02_c=='3'){
			header( "location: question.php?serial=spn02cn" );
		}	
  }
  else if($qus_no =='spn02d'){
  		$spn02_d = $_POST["spn02_d"];
		$sql="UPDATE adult_question set spn02_d='$spn02_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_d=='0'){
			header( "location: question.php?serial=spn02d" );
		}
		elseif($spn02_d=='1'){
			header( "location: question.php?serial=spn02dy" );
		}
		elseif($spn02_d=='3'){
			header( "location: question.php?serial=spn02dn" );
		}	
  }
  else if($qus_no =='spn02e'){
  		$spn02_e = $_POST["spn02_e"];
		$sql="UPDATE adult_question set spn02_e='$spn02_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_e=='0'){
			header( "location: question.php?serial=spn02e" );
		}
		elseif($spn02_e=='1'){
			header( "location: question.php?serial=spn02ey" );
		}
		elseif($spn02_e=='3'){
			header( "location: question.php?serial=spn02en" );
		}	
  }
  
  else if($qus_no =='spn02y'){
  		$spn04_a = $_POST["t1"].$_POST["t2"];
		$spn05_a = $_POST["t3"].$_POST["t4"];
		$spn06_a = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_a='$spn04_a',spn05_a='$spn05_a',spn06_a='$spn06_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_a=='00'||$spn05_a=='00'||$spn06_a=='00'){
			header( "location: question.php?serial=spn02y" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_b']==1) header("location: question.php?serial=spn02b");
				elseif($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02n'){
  		$spn03_a = $_POST["t7"].$_POST["t8"];
  		$spn04_a = $_POST["t1"].$_POST["t2"];
		$spn05_a = $_POST["t3"].$_POST["t4"];
		$spn06_a = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_a='$spn03_a', spn04_a='$spn04_a',spn05_a='$spn05_a',spn06_a='$spn06_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_a=='00'||$spn04_a=='00'||$spn05_a=='00'||$spn06_a=='00'){
			header( "location: question.php?serial=spn02n" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_b']==1) header("location: question.php?serial=spn02b");
				elseif($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02by'){
  		$spn04_b = $_POST["t1"].$_POST["t2"];
		$spn05_b = $_POST["t3"].$_POST["t4"];
		$spn06_b = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_b='$spn04_b',spn05_b='$spn05_b',spn06_b='$spn06_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_b=='00'||$spn05_b=='00'||$spn06_b=='00'){
			header( "location: question.php?serial=spn02by" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02bn'){
  		$spn03_b = $_POST["t7"].$_POST["t8"];
  		$spn04_b = $_POST["t1"].$_POST["t2"];
		$spn05_b = $_POST["t3"].$_POST["t4"];
		$spn06_b = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_b='$spn03_b', spn04_b='$spn04_b',spn05_b='$spn05_b',spn06_b='$spn06_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_b=='00'||$spn04_b=='00'||$spn05_b=='00'||$spn06_b=='00'){
			header( "location: question.php?serial=spn02bn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02cy'){
  		$spn04_c = $_POST["t1"].$_POST["t2"];
		$spn05_c = $_POST["t3"].$_POST["t4"];
		$spn06_c = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_c='$spn04_c',spn05_c='$spn05_c',spn06_c='$spn06_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_c=='00'||$spn05_c=='00'||$spn06_c=='00'){
			header( "location: question.php?serial=spn02cy" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02cn'){
  		$spn03_c = $_POST["t7"].$_POST["t8"];
  		$spn04_c = $_POST["t1"].$_POST["t2"];
		$spn05_c = $_POST["t3"].$_POST["t4"];
		$spn06_c = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_c='$spn03_c', spn04_c='$spn04_c',spn05_c='$spn05_c',spn06_c='$spn06_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_c=='00'||$spn04_c=='00'||$spn05_c=='00'||$spn06_c=='00'){
			header( "location: question.php?serial=spn02cn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02dy'){
  		$spn04_d = $_POST["t1"].$_POST["t2"];
		$spn05_d = $_POST["t3"].$_POST["t4"];
		$spn06_d = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_d='$spn04_d',spn05_d='$spn05_d',spn06_d='$spn06_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_d=='00'||$spn05_d=='00'||$spn06_d=='00'){
			header( "location: question.php?serial=spn02dy" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_e']==1) header("location: question.php?serial=spn02e");	
				else header("location: question.php?serial=gh01");		
		}	
  }
  else if($qus_no =='spn02dn'){
  		$spn03_d = $_POST["t7"].$_POST["t8"];
  		$spn04_d = $_POST["t1"].$_POST["t2"];
		$spn05_d = $_POST["t3"].$_POST["t4"];
		$spn06_d = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_d='$spn03_d', spn04_d='$spn04_d',spn05_d='$spn05_d',spn06_d='$spn06_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_d=='00'||$spn04_d=='00'||$spn05_d=='00'||$spn06_d=='00'){
			header( "location: question.php?serial=spn02dn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02ey'){
  		$spn04_e = $_POST["t1"].$_POST["t2"];
		$spn05_e = $_POST["t3"].$_POST["t4"];
		$spn06_e = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_e='$spn04_e',spn05_e='$spn05_e',spn06_e='$spn06_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_e=='00'||$spn05_e=='00'||$spn06_e=='00'){
			header( "location: question.php?serial=spn02ey" );
		}
		else{
			header("location: question.php?serial=gh01");			
		}	
  }
  else if($qus_no =='spn02en'){
  		$spn03_e = $_POST["t7"].$_POST["t8"];
  		$spn04_e = $_POST["t1"].$_POST["t2"];
		$spn05_e = $_POST["t3"].$_POST["t4"];
		$spn06_e = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_e='$spn03_e', spn04_d='$spn04_e',spn05_e='$spn05_e',spn06_e='$spn06_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_e=='00'||$spn04_e=='00'||$spn05_e=='00'||$spn06_e=='00'){
			header( "location: question.php?serial=spn02en" );
		}
		else{
			header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='gh01'){
  		$gh01 = $_POST["gh01"];
		$sql="UPDATE adult_question set gh01='$gh01' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh01=='0'){
			header( "location: question.php?serial=gh01" );
		}
		elseif($gh01=='1'){
			header( "location: question.php?serial=gh" );
		}
		elseif($gh01=='2'){
			header( "location: question.php?serial=gh02" );
		}	
		elseif($gh01=='3'){
			header( "location: question.php?serial=gh03" );
		}
		
  } 
  else if($qus_no =='gh02'){
  		$gh02 = $_POST["gh02"];
		$sql="UPDATE adult_question set gh02='$gh02' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh02=='0'){
			header( "location: question.php?serial=gh02" );
		}
		elseif($gh02=='1'){
			header( "location: question.php?serial=gh" );
		}	
		else{
			header( "location: question.php?serial=gh03" );
		}
		
  } 
  else if($qus_no =='gh03'){
  		$gh03 = $_POST["t1"].$_POST["t2"];
		$sql="UPDATE adult_question set gh03='$gh03' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh03=='00'){
			header( "location: question.php?serial=gh03" );
		}
		else{
			header( "location: question.php?serial=gh" );
		}				
  }
  else if($qus_no =='gh'){
  		$gh04 = $_POST["gh04"];
		$gh05 = $_POST["gh05"];
		$gh06 = $_POST["gh06"];
		$gh07 = $_POST["gh07"];
		$sql="UPDATE adult_question set gh04='$gh04', gh05='$gh05', gh06='$gh06', gh07='$gh07'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh04=='0'||$gh05=='0'||$gh06=='0'||$gh07=='0'){
			header( "location: question.php?serial=gh" );
		}
		else{
			header( "location: question.php?serial=gh08_a" );
		}				
  } 
  else if($qus_no =='gh08_a'){
  		$gh08_a_1 = $_POST["gh08_a_1"];
		$gh08_a_2 = $_POST["gh08_a_2"];
		$gh08_a_3 = $_POST["gh08_a_3"];
		$gh08_a_4 = $_POST["gh08_a_4"];
		$gh08_a_5 = $_POST["gh08_a_5"];
		$gh08_a_6 = $_POST["gh08_a_6"];
		$gh08_a_7 = $_POST["gh08_a_7"];
		$gh08_a_8 = $_POST["gh08_a_8"];
		$gh08_a_9 = $_POST["gh08_a_9"];
		$sql="UPDATE adult_question set gh08_a_1='$gh08_a_1', gh08_a_2='$gh08_a_2', gh08_a_3='$gh08_a_3',  gh08_a_4='$gh08_a_4',  gh08_a_5='$gh08_a_5', gh08_a_6='$gh08_a_6', gh08_a_7='$gh08_a_7', gh08_a_8='$gh08_a_8', gh08_a_9='$gh08_a_9'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
			header( "location: question.php?serial=cm01a1" );		
  } 
  else if($qus_no =='cm01a1'){
  		//echo "<pre>";
		
		$cm01a1 = $_POST['cm01a1'];
		$d01a1 = $_POST['d01a1'];
		//print_r($cm01a1);
		//exit;
		/*
		$cm01a1_1 = $_POST["cm01a1_1"];
		$cm01a1_2= $_POST["cm01a1_2"];
		$cm01a1_3 = $_POST["cm01a1_3"];
		$cm01a1_4 = $_POST["cm01a1_4"];
		$cm01a1_5 = $_POST["cm01a1_5"];
		$cm01a1_6 = $_POST["cm01a1_6"];
		$cm01a1_7 = $_POST["cm01a1_7"];
		$cm01a1_8= $_POST["cm01a1_8"];
		$cm01a1_9= $_POST["cm01a1_9"];
		$cm01a1_10 = $_POST["cm01a1_10"];
		$cm01a1_11 = $_POST["cm01a1_11"];
		echo $cm01a1_12 = $_POST["cm01a1_12"];
		echo $cm01a1_13 = $_POST["cm01a1_13"];
		$cm01a1_14 = $_POST["cm01a1_14"];
		$cm01a1_15 = $_POST["cm01a1_15"];
		$cm01a1_16 = $_POST["cm01a1_16"];
		$cm01a1_17 = $_POST["cm01a1_17"];
		$cm01a1_18 = $_POST["cm01a1_18"];
		*/
		
		$sql="UPDATE chronic set cm01a1_1='$cm01a1[1]', cm01a1_2='$cm01a1[2]', cm01a1_3='$cm01a1[3]', cm01a1_4='$cm01a1[4]', cm01a1_5='$cm01a1[5]', cm01a1_6='$cm01a1[6]', cm01a1_7='$cm01a1[7]', cm01a1_8='$cm01a1[8]', cm01a1_9='$cm01a1[9]', cm01a1_10='$cm01a1[10]', cm01a1_11='$cm01a1[11]', cm01a1_12='$cm01a1[12]', cm01a1_13='$cm01a1[13]', cm01a1_14='$cm01a1[14]', cm01a1_15='$cm01a1[15]', cm01a1_16='$cm01a1[16]', cm01a1_17='$cm01a1[17]', cm01a1_18='$cm01a1[18]', cm01a1_19='$cm01a1[19]', cm01a1_20='$cm01a1[20]', cm01a1_21='$cm01a1[21]', cm01a1_22='$cm01a1[22]'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		$back =0;
		for($j=1;$j<=22;$j++){
			//echo $cm01a1[$j];
			if($cm01a1[$j]==0){
				 $back=1;
				 break;
			}
		}
		//echo $back;
		if ($back ==1){
			header("location: question.php?serial=cm01a1" );
			exit;
			}
		
		$back =0;
		//echo "test";
		for($i=1;$i<=22;$i++){
			if($cm01a1[$i]=='1'){
				$back =$i;
				break;	 
				 
			}
		}
		if ($back !=0){
			header("location: question.php?serial=cm&no=$i" );
			exit;
			}
		else if ($back ==0){
			header( "location: ../index1.php" );
			exit;
			}		
  }
  else if($qus_no =='cm'){
  		 $no = $_POST['no'];
		 $start=$no+1;	
  		 $cm01a2= $_POST["cm01a2_$no"];
		 $cm02a= $_POST["cm02a_$no"];
		 $cm03a= $_POST["cm03a_$no"];
		 $cm04a= $_POST["cm04a_$no"];
		 $cm05a= $_POST["cm05a_$no"];
		 $cm06a= $_POST["cm06a_$no"];
		
		 $sql="UPDATE chronic set cm01a2_$no='$cm01a2', cm02a_$no='$cm02a', cm03a_$no='$cm03a', cm04a_$no='$cm04a', cm05a_$no='$cm05a', cm06a_$no='$cm06a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
				
		$sql="SELECT * FROM chronic WHERE hid = '$hid' and resp_id = '$respondent'";
				$result = mysql_query($sql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);	
				
		
		if($cm01a2=='0'||$cm02a=='0'||$cm03a=='0'||$cm04a=='0'||$cm05a=='0'||$cm06a=='0'){
			header("location: question.php?serial=cm&no=$no" );
		}
		else{	
			for($i=$start;$i<=22;$i++){
				$z=$row["cm01a1_$i"];
				if($z==1) {
					header("location: question.php?serial=cm&no=$i" );
					exit;
					}
			}	
		}	
			header( "location: ../index1.php" );		
  }
  else if($qus_no =='dm'){
  		 $no = $_POST['no'];
		echo  $start=$no+1;	
  		 $cm01a2= $_POST["d01a2_$no"];
		 $cm02a= $_POST["d02a_$no"];
		 $cm03a= $_POST["d03a_$no"];
		 $cm04a= $_POST["d04a_$no"];
		 $cm05a= $_POST["d05a_$no"];
		 $cm06a= $_POST["d06a_$no"];
		
		 $sql="UPDATE chronic set d01a2_$no='$cm01a2', d02a_$no='$cm02a', d03a_$no='$cm03a', d04a_$no='$cm04a', d05a_$no='$cm05a', d06a_$no='$cm06a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
				
		$sql="SELECT * FROM chronic WHERE hid = '$hid' and resp_id = '$respondent'";
				$result = mysql_query($sql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);	
				
		
		if($cm01a2=='0'||$cm02a=='0'||$cm03a=='0'||$cm04a=='0'||$cm05a=='0'||$cm06a=='0'){
			header("location: question.php?serial=cm&no=$no" );
		}
		else{	
			for($i=$start;$i<=22;$i++){
				$z=$row["cm01a1_$i"];
				if($z==1) {
					header("location: question.php?serial=cm&no=$i" );
					exit;
					}
			}	
		}	
			header( "location: ../index1.php" );		
  }
?>